package com.zpf.service.impl;

import com.zpf.dao.LoginDao;
import com.zpf.dao.impl.LoginDaoImpl;
import com.zpf.pojo.User;
import com.zpf.service.LoginService;
import com.zpf.utils.Constants;

public class LoginServiceImpl implements LoginService {
    LoginDao loginDao = new LoginDaoImpl();

    @Override
    public User login(String username, String password) {
        //根据用户名到数据库查询用户对象
        User user = loginDao.login(username);
        //2.用户名为空则错误
        if (user == null) {
            return null;
        }

        //3.判断激活，未激活，则不让登录
        if(Constants.USER_NOT_ACTIVE.equals(user.getStatus())){
            return null;
        }
        if (password.equals(user.getPassword())) {
            return user;
        }

        return null;
    }

    @Override
    public boolean check(String username) {
        //根据用户名到数据库查询用户对象
        User user = loginDao.login(username);
        //判断是否能查询到
        if (user == null) {
            //用户不存在，可用
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Integer createUser(User user) {
        int count =loginDao.createuser(user);
        return count;
    }
}
